/*******************************************************************************
 * Copyright (c) 2010 Mikhail Garber.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License (LGPL)
 * which accompanies this distribution
 * 
 * Contributors:
 *     Mikhail Garber - initial API and implementation
 ******************************************************************************/
package plumber.model;

import plumber.common.Utils;

/**
 * an Outcome that can match particular value to return value of Step execution
 * @author mgarber
 *
 */
@SuppressWarnings("serial")
public class ValueOutcome extends StepOutcome {

	private Object value;

	/**
	 * set value to match
	 * @param value
	 */
	public void setValue(Object value) {
		this.value = value;
	}

	/**
	 * validate this Outcome; value must be set
	 */
	@Override
	public void validateImpl() {
		Utils.validatePresent(value, "value");

	}

	/**
	 * match the value
	 * will match if they are equal object-wise, or one toString() matches the other
	 * @see plumber.model.StepOutcome#match(java.lang.Object)
	 */
	@Override
	public boolean match(Object val) {
		boolean ret = value.equals(val);
		if(!ret && val != null) {
			ret = value.toString().equals(val.toString());			
		}
		return ret;
	}

}
